package com.ngovanhau.justsort;

import com.ngovanhau.justsort.control.ValueControl;
import com.ngovanhau.justsort.model.LevelSetting;

import android.content.Context;
import android.content.SharedPreferences;

public class MySharedPreferences {

	SharedPreferences.Editor editor;
	SharedPreferences myShare;
	public final static String PREFS_NAME = "09TSortGame";

	public MySharedPreferences(Context context) {
		myShare = context.getSharedPreferences(PREFS_NAME, 0);
		editor = myShare.edit();
	}

	public void getIsMusic() {
		ValueControl.isMusic = myShare.getBoolean("isMusic", true);
	}

	public void getIsSound() {
		ValueControl.isSound = myShare.getBoolean("isSound", true);
	}

	public void getCurrentLevel() {
		LevelSetting.currentLevel = myShare.getInt("currentLevel", 1);
	}

	public void getCurrentType() {
		LevelSetting.currentType = myShare.getInt("currentType", 1);
	}
	
	public void getUnlockType() {
		LevelSetting.unlockType = myShare.getInt("unlockType", 1);
	}

	public void getRowLevel() {
		LevelSetting.rowLevel = myShare.getInt("rowLevel", 3);
	}

	public void getColumnLevel() {
		LevelSetting.columnLevel = myShare.getInt("columnLevel", 3);
	}

	public void updateIsMusic(boolean isMusic) {
		ValueControl.isMusic = isMusic;
		editor.putBoolean("isMusic", isMusic);
		editor.commit();
	}

	public void updateIsSound(boolean isSound) {
		ValueControl.isSound = isSound;
		editor.putBoolean("isSound", isSound);
		editor.commit();
	}

	public void updateCurrentLevel(int currentLevel) {
		LevelSetting.currentLevel = currentLevel;
		editor.putInt("currentLevel", currentLevel);
		editor.commit();
	}

	public void updateCurrentType(int currentType) {
		LevelSetting.currentType = currentType;
		editor.putInt("currentType", currentType);
		editor.commit();
	}
	
	public void updateUnlockType(int unlockType) {
		LevelSetting.unlockType = unlockType;
		editor.putInt("unlockType", unlockType);
		editor.commit();
	}

	public void updateRowLevel(int rowLevel) {
		LevelSetting.rowLevel = rowLevel;
		editor.putInt("rowLevel", rowLevel);
		editor.commit();
	}

	public void updateColumnLevel(int columnLevel) {
		LevelSetting.columnLevel = columnLevel;
		editor.putInt("columnLevel", columnLevel);
		editor.commit();
	}
}
